﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace UlyssesAgenda.GameEngine.Utilities
{
    internal static class StateUtility
    {
        internal static Dictionary<string, string> GetStateFromBinary(byte[] input)
        {
            MemoryStream ms = new MemoryStream(input);
            ms.Position = 0;
            BinaryFormatter bf = new BinaryFormatter();
            return (Dictionary<string, string>)bf.Deserialize(ms);
        }

        internal static byte[] GetBinaryFromState(Dictionary<string, string> input)
        {
            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            bf.Serialize(ms, input);            

            ms.Position = 0;
            return ms.ToArray(); 
        }
    }
}
